function paddingNum (num) {
  let str = '' + num // 转成字符串
  let arr = str.split('.')
  let xiaoshu = ''
  if (arr.length > 1) {
    xiaoshu = arr[1] // 记录小数
  }
  let zhengshu = arr[0]
  zhengshu = zhengshu.split('').reverse()
  let zhengshuStr = []
  let flag = 1
  console.log(zhengshu)
  if (zhengshu[zhengshu.length - 1] === '-') {
    zhengshu.pop()
    flag = 0
  }
  for (let i = 0; i < zhengshu.length; i++) {
    if ((i) % 3 === 0 && i !== 0) {
      zhengshuStr.push(',', zhengshu[i])
    } else {
      zhengshuStr.push(zhengshu[i])
    }
  }
  // console.log(zhengshuStr.reverse().join(''))
  if (xiaoshu !== '') {
    if (flag === 0) {
      return '-' + zhengshuStr.reverse().join('') + '.' + xiaoshu
    } else {
      return zhengshuStr.reverse().join('') + '.' + xiaoshu
    }
  } else {
    if (flag === 1) {
      return zhengshuStr.reverse().join('')
    } else if (flag === 0) {
      let stt = zhengshuStr.reverse.join('')
      return '-' + stt
    }
  }
}
console.log(paddingNum(987654.321))